-
Notifications
You must be signed in to change notification settings - Fork 13.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle GlobalCtxt directly from librustc_interface query system #66791
Conversation
The construction of the GlobalCtxt is moved from a generator's stack to the Queries struct. Since the GlobalCtxt requires the HIR Forest and the arenas to live longer, those are moved into Queries the same way. The resulting handling of objects is more brittle, because consumers of the Once objects need to be careful of their initialisation.
src/librustc_interface/passes.rs
Outdated
|
||
impl BoxedGlobalCtxt { | ||
impl<'gcx> BoxedGlobalCtxt<'gcx> { | ||
pub fn enter<F, R>(&mut self, f: F) -> R | ||
where | ||
F: for<'tcx> FnOnce(TyCtxt<'tcx>) -> R, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this could just be F: FnOnce(TyCtxt<'gcx>) -> R,
now.
ty::tls::enter_global(self.0, |tcx| f(tcx)) | ||
} | ||
|
||
pub fn print_stats(&self) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd just remove this function and let its caller call print_stats
directly using enter
.
src/librustc_interface/queries.rs
Outdated
@@ -74,6 +75,8 @@ pub struct Queries<'comp> { | |||
arenas: Once<AllArenas>, | |||
forest: Once<hir::map::Forest>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can add hir::map::Forest
to the list of types in arena.rs
with a [few]
attribute then we can remove this field and allocate it from Arena
.
This looks good to me now. |
@bors r+ |
📌 Commit 1e12f39 has been approved by |
@@ -740,93 +741,77 @@ pub fn default_provide_extern(providers: &mut ty::query::Providers<'_>) { | |||
rustc_codegen_ssa::provide_extern(providers); | |||
} | |||
|
|||
declare_box_region_type!( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this macro now be removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it's still used for the resolver.
Handle GlobalCtxt directly from librustc_interface query system This PR constructs the `GlobalCtxt` as a member of the `Queries` in librustc_interface. This simplifies the code to construct it, at the expense of added complexity in the query control flow. This allows to handle the arenas directly from librustc_interface. Based on rust-lang#66707 r? @Zoxc
Handle GlobalCtxt directly from librustc_interface query system This PR constructs the `GlobalCtxt` as a member of the `Queries` in librustc_interface. This simplifies the code to construct it, at the expense of added complexity in the query control flow. This allows to handle the arenas directly from librustc_interface. Based on rust-lang#66707 r? @Zoxc
Rollup of 11 pull requests Successful merges: - #66379 (Rephrase docs in for ptr) - #66589 (Draw vertical lines correctly in compiler error messages) - #66613 (Allow customising ty::TraitRef's printing behavior) - #66766 (Panic machinery comments and tweaks) - #66791 (Handle GlobalCtxt directly from librustc_interface query system) - #66793 (Record temporary static references in generator witnesses) - #66808 (Cleanup error code) - #66826 (Clarifies how to tag users for assigning PRs) - #66837 (Clarify `{f32,f64}::EPSILON` docs) - #66844 (Miri: do not consider memory allocated by caller_location leaked) - #66872 (Minor documentation fix) Failed merges: r? @ghost
I think I need help to adjust Miri to these changes... we were using
|
if callbacks.after_analysis(compiler) == Compilation::Stop { | ||
return early_exit(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it maybe a problem that now, after_analysis
is called inside compiler.enter
, so that if the callback needs access to the ctx and calls compiler.enter
itself, we end up with nested compiler.enter
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is indeed the problem. The Callbacks
are supposed to take &'tcx Queries<'tcx>
now to avoid that. So that has to be fixed before Miri can work again. Do you or @cjgillot want to fix that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should probably be an assertion to avoid calling enter
twice too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prepared a PR at #66896 (and tested that this indeed is sufficient to fix Miri).
There should probably be an assertion to avoid calling enter twice too.
I didn't do that as I wouldn't know how.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the delay. Do you still need me to do something?
Don't worry, I am sure you had better things to do on a Saturday morning.
I think we are all set, except for that panic to give a better error when nesting "enter" calls.
|
pass Queries to compiler callbacks rust-lang#66791 made it impossible to access the tcx in the callbacks; this should fix that. r? @Zoxc
This PR constructs the
GlobalCtxt
as a member of theQueries
in librustc_interface.This simplifies the code to construct it, at the expense of added complexity in the query control flow.
This allows to handle the arenas directly from librustc_interface.
Based on #66707
r? @Zoxc